const {PostModel} = require('../../model/PostSchema/PostSchema');

// 添加岗位信息
exports.Add = function (arg) {
    return new Promise((resolve, reject) => {
        const postModel = new PostModel({
            CompanyId: arg.CompanyId,
            PostId:arg.PostId,
            PostTitle: arg.PostTitle,
            PostMoney: arg.PostMoney,
            PostIntroduce: arg.PostIntroduce,
            PostRequirement: arg.PostRequirement,
            PublisherId: arg.PublisherId,
            PostCollectCount: arg.PostCollectCount
        })
        postModel.save((error, result) => {
            if (error) return reject(error)
            resolve(result)
        })
    })
};

/* 查询用户信息(模糊/分页/多条件)
* */
exports.Sel = function (PageNumber, PageSize, arg) {
    return new Promise((resolve, reject) => {
        PostModel.find({...arg}).skip(PageNumber * PageSize).limit(PageSize).exec((error, result) => {
            if (error) return reject(error)
            resolve(result)
        })
    })
};

// 查询文档中的对象/数组的属性
/*
*   @key           需要匹配的键名
*   @value         需要匹配的值
*   @filterOptions 需要过滤的属性
* */
exports.Sel_quoteType = function (key, value, filterOptions) {
    return new Promise((resolve, reject) => {
        PostModel.find({[key]: value}, filterOptions, (error, result) => {
            if (error) return reject(error)
            resolve(result)
        })
    })
}

// 查询count
exports.Sel_Count = function (arg) {
    return new Promise((resolve, reject) => {
        PostModel.count({...arg}, (error, result) => {
            if (error) return reject(error)
            resolve(result)
        })
    })
}

// 修改岗位信息
exports.Upd = function (_id, UpdateObject) {
    return new Promise((resolve, reject) => {
        PostModel.findByIdAndUpdate({_id}, UpdateObject, (error, result) => {
            if (error) return reject(error)
            resolve(result)
        })
    })
}

// 删除岗位信息(删除单条)
exports.Del_One_ById = function (value) {
    return new Promise((resolve, reject) => {
        PostModel.deleteOne({'_id': value}, (error, result) => {
            if (error) return reject(error)
            resolve(result)
        })
    })
}
// 删除岗位信息(删除多条)
exports.Del_Many_ById = function (valueList) {
    return new Promise((resolve, reject) => {
        PostModel.deleteMany({'_id': {$in: valueList}}, (error, result) => {
            if (error) return reject(error)
            resolve(result)
        })
    })
}